﻿#include "ui/control_base.h"
#include "context.h"
#include "texture.h"
#include "shared.h"
#include "draw.h"
#include "font.h"

using namespace std;
using namespace anip;

void ui::Label::paint()
{
	auto textTex = getTextTexture();
	if (textTex == nullptr) return;
	vec2 size = getTextSize();
	Draw::text(_absPos + (_size - size) * align, size, *textTex, textColor);
	WithText::paint();
}

void ui::Label::flow(Flow& f)
{
	if (layoutOptions.type != LayoutOptions::Flow)
	{
		Control::flow(f);
		return;
	}

	vec2 tsize = getTextSize();
	setSize({
		max(tsize.x, layoutOptions.minSize.x),
		max(tsize.y, layoutOptions.minSize.y) });

	if (f.currentX + _size.x > f.borderRight)
		f.newLine();
	f.lineHeight = max(f.lineHeight, _size.y);
	setPosition({ f.currentX, f.currentY });
	f.currentX += _size.x + r::Flow_Separator;
}
